﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASPMVCUtil.Helpers.Html.Grid;
using System.Web.Mvc;

namespace ShowcaseMVC5.Models
{
    public class DateTemplate<TModel> : GridCellTemplate<TModel>
    {
        public override string Draw(object valor, TModel registro)
        {
            return ((DateTime)valor).ToShortDateString();
        }
    }

    public class PriceTemplate<TModel> : GridCellTemplate<TModel>
    {
        public override string Draw(object valor, TModel registro)
        {
            return String.Format("{0:C}", double.Parse(valor.ToString()));
        }
    }

    public class QuantityTemplate<TModel> : GridCellTemplate<TModel>
    {
        public override string Draw(object valor, TModel registro)
        {
            TagBuilder span = new TagBuilder("span");
            if ((int)valor < 10)
            {
                span.MergeAttribute("style", "color: #CC0000");
            }
            else
            {
                span.MergeAttribute("style", "color: #00CC00");
            }
            span.MergeAttribute("title", valor.ToString());
            span.InnerHtml = valor.ToString();
            return span.ToString(TagRenderMode.Normal);
        }
    }
}
